package com.smart.other;


import com.smart.common.entities.constant.SmartConstant;
import com.smart.manager.wiki.entities.models.WikiDocAgreement;
import com.smart.manager.wiki.entities.repository.DocAgreementRepository;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 支付回调处理方法
 * @author xiaxuqiu

 */

@RestController
@RequestMapping(SmartConstant.OTHER_API_PREFIX + "html")
@RequiredArgsConstructor
@Log4j2
@Api(tags = "开放WEB页访")
public class HtmlController {

    private final DocAgreementRepository agreementRepository;
    @GetMapping(value = "agreement/{code}.html")
    @ApiOperation(value = "HTML版协议")
    public String htmlAgreement(@PathVariable String code) {
        WikiDocAgreement result = agreementRepository.readOne(code, true, true);
        String css=".page{background: #FBEEC4; color: #6C3619; }   "
                + ".title{  font-size: 14px; font-weight: bold ;text-align: center;}"
                + ".content {font-size:13px}";


        String tpl = "<!DOCTYPE html><html><head><meta charset=\"utf-8\"/> <style> "+css+"</style>   <title>%s</title></head>" +
                "<body  class=\"page\"><div class=\"title\">%s</div><div class=\"content\">%s</div></body></html>";
        return String.format(tpl, result.getTitle(), result.getTitle(), result.getContent());
    }
}
